<template>
  <div>
    <div>欢迎:{{this.$route.query.sname}}报名选课</div>
<!--    <el-input size="medium" v-model="search_cno" placeholder="请输入课程编号"></el-input>-->
<!--    <el-button @click="search()" icon="el-icon-search" circle></el-button>-->
    <el-table
      :data="tableData"
      border
      style="width:100%">
      <el-table-column
        fixed
        prop="Cno"
        label="科目编号"
        width="150">
      </el-table-column>
      <el-table-column
        prop="Cname"
        label="科目名"
        width="120">
      </el-table-column>
      <el-table-column
        prop="Cperiod"
        label="上课周期"
        width="120">
      </el-table-column>
      <el-table-column
        prop="Cclasshour"
        label="课节数"
        width="120">
      </el-table-column>
      <el-table-column
        prop="Cpayment"
        label="上课费用"
        width="120">
      </el-table-column>
      <el-table-column
        prop="Cplace"
        label="上课地点"
        width="120">
      </el-table-column>
      <el-table-column
        prop="Tno"
        label="教师编号"
        width="120">
      </el-table-column>
      <el-table-column
        prop="Cneed"
        label="招收人数"
        width="120">
      </el-table-column>
      <el-table-column
        prop="Cjoin"
        label="已报名人数"
        width="120">
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            size="mini"
            @click="handleSign(scope.row)">报名</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  created(){
    const _this = this;
    this.axios.post('http://localhost:8152/api/auth/course/findall').then((res) => {
      _this.tableData = res.data
      //_this.total = res.data.totalElements
    })
  },
  methods: {
    // search(){
    //   const  _this = this;
    //   this.$axios.get(`/course/list?cno=${this.search_cno}`).then((res) => {
    //     console.log(res.data);
    //     _this.tableData = res.data;
    //
    //   })
    // },
    handleSign(row) {
      console.log(row.Cno,this.$route.query.sname)
      this.axios.post('http://localhost:8152/api/auth/choosecourse',{Cno:row.Cno,Sname:this.$route.query.sname}).then((res) => {
        console.log(res.data.msg)
        if(res.data.msg == '报名成功'){
          alert("报名成功，请去缴费");
          console.log(res.data.Cname),
          this.$router.push({path:'/pay',query:{
              Cno: row.Cno,
              Sname:this.$route.query.sname
            }});
        }else if(res.data.msg == '已经报名') {
          alert("已经报名，不可重报");
        } else {
          alert("该科目已经满员，请选择别的科目或者报名下期培训")
        }
      });

    },
  },

  data() {
    return {
      search_cno :'',
      tableData: null
    }
  }
}
</script>
